<?php


namespace App\Services\Result;

use App\Interf\Resultable;
use Monolog\Logger;
use ParamConfig;

use App\Services\Result\BaseResult;
use ResultTypeService;

use App\Models\LogHelper;

class AndropauseTestingResult extends BaseResult implements Resultable
{
    private $answers;

    private $totalSummaryAttrObj;
    private $note;
    private $score;

    public function __construct($tid, $uid, $score, $resultTypeIdArr, $finalAnswerStr)
    {

        $this->answers = $this->convertAnswer($finalAnswerStr);
        $this->totalSummaryAttrObj = $this->configAttrObj(1, '结果分析');

        $this->note = ResultTypeService::getResult($uid, $resultTypeIdArr, $score, $tid);
        $this->score = $score;

    }


    public function result()
    {
        $attrs = [];
        array_push($attrs, $this->totalSummaryAttr());
        $data['attrs'] = $attrs;
        $data['chatparam'] = $this->getChatparam();
        //图类型为雷达图
        $data['chatType'] = '';

        return $data;

    }


    /**
     * @return array
     */
    protected function totalSummaryAttr()
    {


        $needProcessNote = $this->note[0]['attributes']['note'];
        $processedNote = $this->processNote($needProcessNote);
        $obj = $this->totalSummaryAttrObj;
        $obj = $this->compactAttrObj($obj['attr_id'], $obj['title'], $processedNote);
        LogHelper::log($obj);

        return $obj;
    }

    public function processNote($needProcessNote)
    {
        $processedNote = str_replace('@13', $this->score, $needProcessNote);
        $name = $this->getAnswerObjByIndex($this->answers, 12);
        $processedNote = str_replace('$12', $name['answer'], $processedNote);
        return $processedNote;
    }


    protected function getChatparam()
    {
        $chatdata = [];
        return $chatdata;
    }


}